package com.spider.im.common.constant;

import lombok.Getter;

/**
 * 返回码枚举
 */
@Getter
public enum RespCodeEnum {
    SUCCESS(200, "成功"),
    FAIL(500, "系统异常"),
    SENT_MSM_ERROR(10001, "发送短信异常"),
    REDIS_LOCK(101001, "业务繁忙，稍后重试"),
    REDIS_ERROR_LOCK(101002, "加锁失败"),
    USER_EXIST(20001, "用户已存在"),
    USER_NOT_EXIST(20002, "用户不存在"),
    USER_PASSWORD_ERROR(20003, "用户密码错误"),
    USER_NOT_LOGIN(20004, "用户未登录"),
    USER_NOT_FOUND(20005, "用户未找到"),
    USER_NOT_EXIST_OR_PASSWORD_ERROR(20006, "用户不存在或密码错误"),
    USER_TOKEN_ERROR(20007, "token error"),
    VERIFICATION_CODE_EXPIRED(20008, "验证码错误"),
    PHONE_NOT_NULL(20009, "电话号码不能为空"),
    PASSWORD_NOT_NULL(20010, "密码不能为空"),

    ENCRYPT_ERROR(11001, "加密失败"),
    DECRYPT_ERROR(11002, "解密失败"), ;
    private final Integer code;
    private final String desc;
    private RespCodeEnum(Integer code, String desc) {
        this.code = code;
        this.desc = desc;
    }

    /**
     * 根据编码获取枚举描述，如果没有匹配的编码，则返回null
     */
    public static String getDescByCode(Integer code) {
        for (RespCodeEnum value : values()) {
            if (value.code.equals(code)) {
                return value.desc;
            }
        }
        return null;
    }

}
